package com.hyt.it.ogt.controller.ykcj.system;

import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hyt.it.ogt.controller.base.BaseController;
import com.hyt.it.ogt.ykcj.common.core.domain.AjaxResult;
import com.hyt.it.ogt.ykcj.common.core.page.TableDataInfo;
import com.hyt.it.ogt.ykcj.common.utils.StringUtils;
import com.hyt.it.ogt.ykcj.domain.system.SysDistrict;
import com.hyt.it.ogt.ykcj.service.system.ISysDistrictService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiSort;

/**
 * 行政区划Controller
 * 
 * @author admin
 * @date 2021-09-09
 */
@Api(tags = "system.5.行政区划", value = "行政区划请求接口")
@ApiSort(value = 405)
@RestController
@RequestMapping("/system/district")
public class SysDistrictController extends BaseController
{
    @Autowired
    private ISysDistrictService sysDistrictService;

    /**
     * 查询行政区划列表
     */
    @ApiOperation("查询行政区划列表")
    @GetMapping("/list")
    public TableDataInfo list(SysDistrict sysDistrict)
    {
        startPage();
        List<SysDistrict> list = sysDistrictService.selectSysDistrictList(sysDistrict);
        return getDataTable(list);
    }


    /**
     * 获取行政区划详细信息
     */
    @ApiOperation("获取行政区划详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(sysDistrictService.selectSysDistrictById(id));
    }


    /**
     * 获取省份列表
     */
    @ApiOperation("获取省份列表")
    @GetMapping("/getProvince")
    public AjaxResult getProvince()
    {
        List<SysDistrict> list = sysDistrictService.getProvince();
        if (CollectionUtils.isEmpty(list))
            return AjaxResult.error();
        return AjaxResult.success(list);
    }

    /**
     *获取下级行政区信息
     */
    @ApiOperation("获取下级行政区信息")
    @GetMapping("/getInfoById")
    public AjaxResult getInfoById(SysDistrict sysDistrict)
    {
        if (StringUtils.isEmpty(sysDistrict.getId()))
            return AjaxResult.error("Id为空");
        List<SysDistrict> list = sysDistrictService.getInfoById(sysDistrict.getId());
        return AjaxResult.success(list);
    }
}
